#!/usr/bin/python -i

# python with pdffit2 loaded - as students are accustomed to

from diffpy.pdffit2 import PdfFit
import sys
import site

# setup tab completion and history file when readline is available
try:
    import readline
except ImportError:
    pass
else:
    # tab completion
    import rlcompleter
    import os.path
    readline.parse_and_bind("tab: complete")
    # record history
    histfile = os.path.expanduser('~/.pdffit2hist')
    try:
        readline.read_history_file(histfile)
    except IOError:
        pass
    import atexit
    atexit.register(readline.write_history_file, histfile)
    del histfile

# prompt setup
sys.ps1 = "pdffit2> "

# create PdfFit instance and export its members to global namespace
_P = PdfFit()
_P._exportAll(locals())

# make exit() available
from sys import exit

# alias to allow help(pdffit)
eolkey = (sys.platform == "win32" and "<Ctrl-Z>" or "<Ctrl-D>")
pdffit = PdfFit
print
print '        Type  help(pdffit)  or  help(topic)  for information.'
print '        Type  exit()  or  %s  to exit.\n' % eolkey


# execute the first argument
if len(sys.argv) > 1:
    del sys.argv[0]
    execfile(sys.argv[0])
